package com.shell.provider;

import com.shell.bee.base.utils.JsonUtil;
import com.shell.dto.UserAndOrganDto;
import com.shell.governor.user.dao.PubUserOrganDao;
import com.shell.governor.user.po.PubUserOrgan;
import com.shell.governor.user.service.PubUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserOrganProvider {
	
	@Autowired
	PubUserService userService;
	@Autowired
	PubUserOrganDao userOrganDao;

	@RequestMapping({ "/user-organ/saveOrUpdateUserAndOrgan" })
	void saveOrUpdateUserAndOrgan(String userAndOrganDtoJson) throws Exception {
		UserAndOrganDto userAndOrganDto = (UserAndOrganDto) JsonUtil.fromJson(userAndOrganDtoJson,
				UserAndOrganDto.class);
		this.userService.saveOrUpdateUserAndOrgan(userAndOrganDto);
	}

	@RequestMapping(value = { "/user-organ/getUserOrganByInviteCode" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.GET })
	PubUserOrgan getUserOrganByInviteCode(@RequestParam("inviteCode") String inviteCode) {
		return this.userOrganDao.getUserOrganByInviteCode(inviteCode);
	}
}
